﻿using AutoMapper;
using B.S.Sterilizationcenter.Domain.yjb;
using B.S.Sterilizationcenter.ErrorCode;
using Dm;
using MediatR;
using SqlSugar;

namespace B.S.Sterilizationcenter.Writer.API.FileNlog
{
    public class Nolgs
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;

        public Nolgs(ISqlSugarClient db,IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }



        /// <summary>
        /// 日志调用
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ApiResult<Nlog>> GetNlogs(string UserName, string LogType, string? Respsestate, int Duration, string? ExcepMessage)
        {
            try
            {
                ApiResult<Nlog> result = new ApiResult<Nlog>();
                var log = new Nlog
                {
                    CreateTime = DateTime.Now,
                    UserName = UserName,
                    LogType = LogType,
                    Respsestate = Respsestate,
                    Duration = Duration,
                    ExcepMessage = ExcepMessage,
                    IsDeleted = false,
                };
                var model = mapper.Map<Nlog>(log);
                await db.Insertable(model).ExecuteCommandAsync();
                return result;

            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
